package com.hdhere.core.configuration;

import com.hdhere.core.data.UserAuditor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

/**
 * Created by dus on 2018/12/14.
 */
@Configuration
@EnableJpaAuditing
@ConditionalOnClass(value=JpaRepository.class, name={"org.springframework.orm.jpa.AbstractEntityManagerFactoryBean"})
@ConditionalOnProperty(name = "spring.data.jpa.audit.open", havingValue = "true", matchIfMissing = true)
public class JpaConfig {

    @ConditionalOnWebApplication
    @Bean
    public UserAuditor auditorProvider() {

        return new UserAuditor();
    }
}
